package xin.marcher.module.replenished.api.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.exception.ProductBizException;
import xin.marcher.module.replenished.api.AvailableApi;
import xin.marcher.module.replenished.domain.request.AvailableRequest;
import xin.marcher.module.replenished.service.AvailableService;

import javax.annotation.Resource;

/**
 * 商品可售实现
 *
 *
 */
@Slf4j
@DubboService(version = "1.0.0", interfaceClass = AvailableApi.class, retries = 0)
public class AvailableApiImpl implements AvailableApi {

    @Resource
    private AvailableService availableService;

    @Override
    public JsonResult syncAvailableProduct(AvailableRequest request) {
        try {
            Boolean success = availableService.syncAvailableProduct(request);
            return JsonResult.buildSuccess(success);
        } catch (ProductBizException e) {
            log.error("biz error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
